from django.db import models
from apps.base.models import ProductSource


# Create your models here.
# 上传产品文档
class SupplierTDS(models.Model):
    def upload_to(self, filename):
        return f'documents/product_bank/{self.F001.pk}/{filename}'

    F001 = models.OneToOneField(ProductSource, on_delete=models.CASCADE, verbose_name='产品型号')
    File = models.FileField(upload_to=upload_to, null=True, verbose_name='文件')

    class Meta:
        verbose_name = '供应商产品文档'
        verbose_name_plural = verbose_name


class TDS(models.Model):
    def upload_to(self, filename):
        return f'documents/tds/{self.F001.A001}/{filename}'

    F001 = models.ForeignKey(ProductSource, on_delete=models.CASCADE, verbose_name='产品型号')
    File = models.FileField(upload_to=upload_to, null=True, verbose_name='文件')

    class Meta:
        verbose_name = '供应商物性表'
        verbose_name_plural = verbose_name


class OurTDS(models.Model):
    def upload_to(self, filename):
        return f'documents/OurTDS/{self.F001.A001}/{filename}'

    F001 = models.ForeignKey(ProductName, on_delete=models.CASCADE)
    File = models.FileField(upload_to=upload_to, null=True)

    class Meta:
        verbose_name = '我方物性表'
        verbose_name_plural = verbose_name
